package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lhh
 * @ClassName BaseTrademarkController
 * @date 2022 2022/12/1
 */
@Api(tags = "品牌接口")
@RestController
@RequestMapping("admin/product")
public class BaseTrademarkController {

    @Resource
    BaseTrademarkService baseTrademarkService;

    @ApiOperation(value = "获取品牌分页列表")
    @GetMapping("baseTrademark/{page}/{limit}")
    public Result getBaseTrademark(@PathVariable Integer page,@PathVariable Integer limit){
        Page<BaseTrademark> trademarkPage = new Page<>(page,limit);
        trademarkPage = baseTrademarkService.page(trademarkPage);
        return Result.ok(trademarkPage);
    }

    @ApiOperation(value = "添加品牌")
    @PostMapping("baseTrademark/save")
    public Result save(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    @ApiOperation(value = "根据Id获取品牌")
    @GetMapping("baseTrademark/get/{id}")
    public Result findById(@PathVariable Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    @ApiOperation(value = "修改品牌")
    @PutMapping("baseTrademark/update")
    public Result updateBaseTrademark(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    @ApiOperation(value = "删除品牌")
    @DeleteMapping("baseTrademark/remove/{id}")
    public Result remove(@PathVariable Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    @ApiOperation(value = "获取品牌属性")
    @GetMapping("baseTrademark/getTrademarkList")
    public Result getTrademarkList(){
        List<BaseTrademark> list = baseTrademarkService.list();
        return  Result.ok(list);
    }
}
